<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6"><![endif]-->
<!--[if IE 7 ]><html class="ie ie7"><![endif]-->
<!--[if IE 8 ]><html class="ie ie8"><![endif]-->
<!--[if IE 9 ]><html class="ie ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html><!--<![endif]-->
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="initial-scale=1,minimum-scale=1" />
	<title>交广领航管理平台</title>
	<c:import url="/public/head-tag.jsp"/>
	<link rel="stylesheet" href="/pages/assets/css/platform.css?v=2016" />
	<style>
	html,body{
		height:100%;
		position:static;
	}
	iframe{
		border:0;
		width:100%;
		height:100%;
		position:absolute;
		top:0;
		left:-100%;
		opacity:0;
		z-index:0;
	}
	.active{
		opacity:1;
		z-index:1;
		left:0;
	}
	</style>
</head>
<body>
<iframe  id="mainFrame1"  frameborder="0"></iframe>
<iframe id="mainFrame2" frameborder="0" ></iframe>
<script src="/pages/assets/js/libs/jwplayer/jwplayer7.js"></script>
<script>


	var jplayer=null;
	var $frame1=$('#mainFrame1'), $frame2=$('#mainFrame2');
	var $activeFrame=$frame1;
	var isFirst=true;
	
	function updateVideoButton(cb){
		var $button = $('#btn-rtmp', getActiveFrame()[0].contentDocument);
		if($button.length==0) $button = $('#btn-rtmp', getHiddenFrame()[0].contentDocument);
		cb($button)
	}
	
	function playSound(){
		console.log('播放声音提醒')
	}
	
	function playVideo(){
		
		if(!jplayer){
			
			$.getScript('/pages/assets/js/live/video-frame.js', function(){
				
				window.jplayer=new JVideo({
					
					onShow:function(){
						updateVideoButton(function($button){
							$button.text('正在直播').attr('title', '点击暂停直播').addClass('btn-rtmp-active')
						})
					},
					
					onHide:function(){
						updateVideoButton(function($button){
							$button.text('打开直播').removeAttr('title').removeClass('btn-rtmp-active');
						})
					},
					
					ready:function(){
						this.show();
					}
				})
			})
		}else{
			jplayer.toggle();
		}
	}
	
	function hide($el){
		$el.removeClass();
		return $el;
	}
	
	function show($el){
		$el.addClass('active');
		return $el;
	}
	
	function getActiveFrame(){
		if($frame1.hasClass('active')) return $frame1;
		if($frame2.hasClass('active')) return $frame2;
		return show($frame1);
	}
	
	function getHiddenFrame(){
		if(!$frame1.hasClass('active')) return $frame1;
		if(!$frame2.hasClass('active')) return $frame2;
		return hide($frame1);
	}
	
	function changePage(){
		if(isFirst){
			 isFirst=false;
			 return;
		}
		
		console.log('switchPage...')
		var $show=getHiddenFrame(), $hide=getActiveFrame();
		show($show);
		hide($hide);
		
		if(jplayer) {
			updateVideoButton(function($button){
				if(jplayer.isPlaying())
					$button.text('正在直播').attr('title', '点击暂停直播').addClass('btn-rtmp-active')
				else 
					$button.text('打开直播').removeAttr('title').removeClass('btn-rtmp-active');
			})
		}
	}
	
	function switchPage(){
		if(isFirst){
			 isFirst=false;
			 return;
		}
		
		clearTimeout(switchPage.timecode);
		switchPage.timecode=setTimeout(function(){
			changePage();
		}, 100)
		
		
	}
	
	function loadPage(url, $frame){
		console.log('loadPage:', url)
		$frame.attr('src', url);
	}
	
	(function(){
		
		if(window.parent!=window.top) {
			window.parent.location.href=location.href;
			return;
		}
		
		window.onhashchange=function(){
			
		}

		$('iframe').on('load', function(){
			var $this=$(this);
			$($this[0].contentDocument).find('.tab-labels-large a').on('click', function(e){
				e.preventDefault();
				var url = $(e.target).attr('href');
				//console.log('click:', url)
				loadPage(url, getHiddenFrame())
			})
			switchPage()
		})
		
		var url = location.hash.replace(/^#/, '') || '/Manager/web/zbpt/page';
		loadPage(url, getActiveFrame());
	}())
</script>
</body>
</html>